<html xmlns:th="http://www.thymeleaf.org" xmlns:layout="http://www.ultraq.net.nz/web/thymeleaf/layout"
      layout:decorator="base/layout.html">

<!-- start: Content -->
<div layout:fragment="content" class="main sidebar-minified">

    <div class="row">
        <div class="col-lg-12">
            <ol class="breadcrumb">
                <li><i class="fa fa-home"></i><a th:href="@{../infoManage/indexTotal}">首页</a></li>
                <li><i class="fa fa-table"></i>企业信息管理</li>
            </ol>
        </div>
    </div>


    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h2><i class="fa fa-indent red"></i><strong>查询信息</strong></h2>
                </div>
                <div class="panel-body">
                    <form id="modularForm" th:action="@{../workInfo/queryWorkInfo}" method="post"
                          class="form-horizontal " role="form">


                        <div class="form-group">
                            <label class="col-lg-2 col-md-2 col-sm-12 control-label">承办部门</label>

                            <div class="col-lg-10 col-md-10">
                                <div class="row">
                                    <div class="col-lg-2 col-md-2">
                                        <select id="selectDepartment" name="departmentid" class="form-control" size="1">

                                        </select>
                                    </div>

                                    <label class="col-lg-2 col-md-2 col-sm-12 control-label">合作单位名称</label>
                                    <div class="col-lg-2 col-md-2">
                                        <input type="text" id="unitscooperativename" name="unitscooperativename"
                                               class="form-control" th:value="${queryMap['unitscooperativename']}">
                                    </div>


                                    <button id="submitBtn" type="submit" class="btn btn-sm btn-success"><i
                                            class="fa fa-dot-circle-o"></i> 查询
                                    </button>
                                    <button id="resetBtn" type="button" class="btn btn-sm btn-danger"><i
                                            class="fa fa-ban"></i> 重置
                                    </button>
                                    <button id="exportBtn" type="button" class="btn btn-sm btn-primary"><i
                                            class="fa fa-ban"></i> 导出excel
                                    </button>
                                </div>

                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-lg-2 col-md-2 col-sm-12 control-label">合作单位性质</label>

                            <div class="col-lg-10 col-md-10">
                                <div class="row">
                                    <div class="col-lg-2 col-md-2">
                                        <select id="selectUnitsNature" name="unitsnatureid" class="form-control"
                                                size="1">

                                        </select>
                                    </div>

                                    <label class="col-lg-2 col-md-2 col-sm-12 control-label">企业类型</label>
                                    <div class="col-lg-2 col-md-2">
                                        <select id="selectCooperativeType" name="cooperativetypeid" class="form-control"
                                                size="1">

                                        </select>
                                    </div>


                                </div>

                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-lg-2 col-md-2 col-sm-12 control-label">企业规模</label>

                            <div class="col-lg-10 col-md-10">
                                <div class="row">
                                    <div class="col-lg-2 col-md-2">
                                        <select id="selectScaleInfo" name="scaleid" class="form-control" size="1">

                                        </select>
                                    </div>

                                    <label class="col-lg-2 col-md-2 col-sm-12 control-label">外资属性</label>
                                    <div class="col-lg-2 col-md-2">
                                        <select id="selectForeignProperty" name="foreignpropertyid" class="form-control"
                                                size="1">

                                        </select>
                                    </div>


                                </div>

                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-lg-2 col-md-2 col-sm-12 control-label">行政区属</label>

                            <div class="col-lg-10 col-md-10">
                                <div class="row">
                                    <div class="col-lg-2 col-md-2">
                                        <select id="selectAdministrativeDistrict" name="administrativedistrictid"
                                                class="form-control" size="1">

                                        </select>
                                    </div>

                                    <label class="col-lg-2 col-md-2 col-sm-12 control-label">是否签署合作协议</label>
                                    <div class="col-lg-2 col-md-2">
                                        <select id="signagreement" name="signagreement" class="form-control" size="1">
                                            <option value="-1">请选择</option>
                                            <option value="1" th:selected="${queryMap['signagreement']} eq 1">是</option>
                                            <option value="2" th:selected="${queryMap['signagreement']} eq 2">否</option>
                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>


                        <div class="form-group">
                            <label class="col-lg-2 col-md-2 col-sm-12 control-label">项目分类</label>

                            <div class="col-lg-10 col-md-10">
                                <div class="row">
                                    <div class="col-lg-2 col-md-2">
                                        <select id="selectProjectType" name="projecttypeid" class="form-control"
                                                size="1">

                                        </select>
                                    </div>

                                    <label class="col-lg-2 col-md-2 col-sm-12 control-label">企业所在地</label>
                                    <div class="col-lg-2 col-md-2">
                                        <select id="selectEnterpriseLocation" name="enterpriselocationid"
                                                class="form-control" size="1">

                                        </select>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <div class="form-group">
                            <label class="col-lg-2 col-md-2 col-sm-12 control-label">协议签署时间</label>
                            <div class="col-lg-10 col-md-10">
                                <div class="row">
                                    <div class="col-lg-2 col-md-2">
                                        <input type="text" class="form-control date-picker" id="beginSignagreement"
                                               name="beginSignagreement" readonly
                                               th:value="${queryMap['beginSignagreement']}" placeholder="起始时间">

                                    </div>
                                    <label class="col-lg-1 col-md-1 col-sm-1 control-label"
                                           style="text-align: center">-</label>
                                    <div class="col-lg-2 col-md-2">
                                        <input type="text" class="form-control date-picker" id="endSignagreement"
                                               name="endSignagreement" readonly
                                               th:value="${queryMap['endSignagreement']}" placeholder="终止时间">
                                    </div>
                                </div>
                            </div>


                        </div>


                    </form>
                </div>
            </div>
        </div><!--.col-->
    </div><!--.row-->

    <div class="row">
        <div class="col-lg-12">
            <div class="panel panel-default">
                <div class="panel-heading">
                    <h2><i class="fa fa-table red"></i><span class="break"></span><strong>企业信息管理</strong></h2>

                </div>
                <div class="panel-body">
                    <table class="table table-bordered bootstrap-datatable datatable">
                        <thead>
                        <tr>
                            <td>序号</td>
                            <th>承办部门</th>
                            <th>合作单位名称</th>
                            <th>企业联系人</th>
                            <th>协议签署时间</th>
                            <th>操作</th>
                        </tr>
                        </thead>
                        <tbody>


                        <tr th:each="workInfo,state  : ${workInfoList}" th:id="${'tr1'+ workInfo.id}">
                            <td th:text="${state.index+1}"></td>
                            <td th:if="${#lists.isEmpty(workInfo.department)}"></td>
                            <td th:unless="${#lists.isEmpty(workInfo.department)}"
                                th:text="${workInfo.department.department}"></td>
                            <td th:text="${workInfo.unitscooperativename}"></td>
                            <td th:text="${workInfo.contactsname}"></td>
                            <td th:text="${#dates.format(workInfo.signtime,'yyyy-MM-dd')}"></td>

                            <td>
                                <a class="btn btn-success" id="SeeBtn" th:value="${workInfo.id}"
                                   th:onclick="'layerOpen(\'toWorkInfoDetail?id='+${workInfo.id}+'\'),getVal('+${workInfo.id}+')'">
                                    <i class="fa fa-search-plus "></i>
                                </a>
                                <a th:if="${session.userInfo.departmentid == workInfo.departmentid||session.userInfo.departmentid == 11 }"
                                   class="btn btn-info" th:href="@{../workInfo/toWorkInfoUpdate(id=${workInfo.id})}">
                                    <i class="fa fa-edit "></i>
                                </a>
                                <a th:if="${session.userInfo.departmentid == workInfo.departmentid||session.userInfo.departmentid == 11 }"
                                   class="btn btn-danger" th:onclick="'deleteWorkInfo('+${workInfo.id}+')'">
                                    <i class="fa fa-trash-o "></i>

                                </a>
                            </td>

                        </tr>


                        </tbody>
                    </table>
                    <!-- 分页 -->
                    <div th:unless="${#lists.isEmpty(workInfoList)}">

                        <div

                                th:replace="base/pagination :: pagination('queryWorkInfo')"></div>
                    </div>

                </div>
            </div>
        </div><!--/col-->

    </div><!--/row-->


    <script>

        $(document).ready(function () {

            //加载到期
            initMaturity();
            //加载承办部门
            initDepartment();
            //加载行政区属
            initAdministrativeDistrict();
            //加载企业所在地
            initEnterpriseLocation();
            //加载合作单位性质
            initUnitsNature();
            //加载企业类型
            initCooperativeType();
            //加载企业规模
            initScale();
            //加载外资属性
            initForeignProperty();
            //加载项目分类
            initProjectType();
            //加载时间控件
            setDatePicker("#beginSignagreement");
            setDatePicker("#endSignagreement");
        });


        //加载到期
        function initMaturity() {
            $.ajax({
                url: '../workInfo/selectMaturity',
                type: 'get',
                dataType: 'json',
                data: {},
                success: function (data) {
                    for (var i = 0; i < data.length; i++) {
                        if (data[i].expirationtips == 1) {
                            $('#tr1' + data[i].id).css("background-color", "#FFE4B5")
                        }
                    }
                }
            })
        }

        //加载承办部门
        function initDepartment() {

            //获取部门id
            var departmentid = "[[${queryMap['departmentid']}]]";

            $("#selectDepartment").append("<option value=-1>请选择</option>");
            $.ajax({
                url: '../department/selectDepartmentInfo',
                type: 'get',
                dataType: 'json',
                data: {},
                success: function (data) {
                    //如果部门id是空
                    if (departmentid == undefined || departmentid == null || departmentid == "") {
                        for (var i in data) {

                            $("#selectDepartment").append("<option value=" + data[i].id + ">" + data[i].department + "</option>");

                        }
                    }
                    else {
                        for (var i in data) {
                            if (departmentid == data[i].id) {
                                $("#selectDepartment").append("<option value=" + data[i].id + " selected>" + data[i].department + "</option>");
                            }
                            else {
                                $("#selectDepartment").append("<option value=" + data[i].id + ">" + data[i].department + "</option>");
                            }
                        }
                    }
                }
            })
        }

        //加载行政区属
        function initAdministrativeDistrict() {
            var administrativedistrictid = "[[${queryMap['administrativedistrictid']}]]";
            $("#selectAdministrativeDistrict").append("<option value=-1>请选择</option>");
            $.ajax({
                url: '../administrativeDistrict/SelectAdministrativeDistrictInfo',
                type: 'get',
                dataType: 'json',
                data: {},
                success: function (data) {
                    if (administrativedistrictid == undefined || administrativedistrictid == null || administrativedistrictid == "") {
                        for (var i in data) {
                            $("#selectAdministrativeDistrict").append("<option value=" + data[i].id + ">" + data[i].administrativedistrict + "</option>");
                        }
                    } else {
                        for (var i in data) {
                            if (administrativedistrictid == data[i].id) {
                                $("#selectAdministrativeDistrict").append("<option value=" + data[i].id + " selected>" + data[i].administrativedistrict + "</option>")
                            } else {
                                $("#selectAdministrativeDistrict").append("<option value=" + data[i].id + ">" + data[i].administrativedistrict + "</option>")
                            }
                        }
                    }
                }
            })
        }

        //加载企业所在地
        function initEnterpriseLocation() {
            var enterpriselocationid = "[[${queryMap['enterpriselocationid']}]]";
            $("#selectEnterpriseLocation").append("<option value=-1>请选择</option>");
            $.ajax({
                url: '../enterpriseLocation/SelectEnterpriseLocationInfo',
                type: 'get',
                dataType: 'json',
                data: {},
                success: function (data) {
                    if (enterpriselocationid == undefined || enterpriselocationid == null || enterpriselocationid == "") {
                        for (var i in data) {
                            $("#selectEnterpriseLocation").append("<option value=" + data[i].id + ">" + data[i].enterpriselocation + "</option>");
                        }
                    } else {
                        for (var i in data) {
                            if (enterpriselocationid == data[i].id) {
                                $("#selectEnterpriseLocation").append("<option value=" + data[i].id + " selected>" + data[i].enterpriselocation + "</option>")
                            } else {
                                $("#selectEnterpriseLocation").append("<option value=" + data[i].id + ">" + data[i].enterpriselocation + "</option>")
                            }
                        }
                    }
                }
            })

        }

        //加载合作单位性质
        function initUnitsNature() {

            //获取合作单位性质id
            var unitsnatureid = "[[${queryMap['unitsnatureid']}]]";

            $("#selectUnitsNature").append("<option value=-1>请选择</option>");
            $.ajax({
                url: '../unitsNature/selectUnitsNatureInfo',
                type: 'get',
                dataType: 'json',
                data: {},
                success: function (data) {

                    if (unitsnatureid == undefined || unitsnatureid == null || unitsnatureid == "") {
                        for (var i in data) {
                            $("#selectUnitsNature").append("<option value=" + data[i].id + ">" + data[i].name + "</option>");
                        }
                    }
                    else {
                        for (var i in data) {

                            if (unitsnatureid == data[i].id) {
                                $("#selectUnitsNature").append("<option value=" + data[i].id + " selected>" + data[i].name + "</option>");
                            }
                            else {

                                $("#selectUnitsNature").append("<option value=" + data[i].id + ">" + data[i].name + "</option>");

                            }
                        }
                    }


                }
            })

        }

        //加载企业类型
        function initCooperativeType() {

            var cooperativetypeid = "[[${queryMap['cooperativetypeid']}]]";

            $("#selectCooperativeType").append("<option value=-1>请选择</option>");
            $.ajax({
                url: '../cooperativeType/selectCooperativeTypeInfo',
                type: 'get',
                dataType: 'json',
                data: {},
                success: function (data) {

                    if (cooperativetypeid == undefined || cooperativetypeid == null || cooperativetypeid == "") {
                        for (var i in data) {
                            $("#selectCooperativeType").append("<option value=" + data[i].id + ">" + data[i].type + "</option>");
                        }
                    }
                    else {
                        for (var i in data) {
                            if (cooperativetypeid == data[i].id) {
                                $("#selectCooperativeType").append("<option value=" + data[i].id + " selected>" + data[i].type + "</option>");
                            }
                            else {
                                $("#selectCooperativeType").append("<option value=" + data[i].id + ">" + data[i].type + "</option>");
                            }


                        }
                    }

                }
            })

        }

        //加载企业规模
        function initScale() {

            var scaleid = "[[${queryMap['scaleid']}]]";

            $("#selectScaleInfo").append("<option value=-1>请选择</option>");
            $.ajax({
                url: '../scale/selectScaleInfo',
                type: 'get',
                dataType: 'json',
                data: {},
                success: function (data) {

                    if (scaleid == undefined || scaleid == null || scaleid == "") {
                        for (var i in data) {

                            $("#selectScaleInfo").append("<option value=" + data[i].id + ">" + data[i].scale + "</option>");
                        }
                    }
                    else {
                        for (var i in data) {

                            if (scaleid == data[i].id) {
                                $("#selectScaleInfo").append("<option value=" + data[i].id + " selected>" + data[i].scale + "</option>");
                            }
                            else {
                                $("#selectScaleInfo").append("<option value=" + data[i].id + ">" + data[i].scale + "</option>");
                            }


                        }
                    }


                }
            })

        }

        //加载外资属性
        function initForeignProperty() {

            var foreignpropertyid = "[[${queryMap['foreignpropertyid']}]]";

            $("#selectForeignProperty").append("<option value=-1>请选择</option>");
            $.ajax({
                url: '../foreignProperty/selectForeignPropertyInfo',
                type: 'get',
                dataType: 'json',
                data: {},
                success: function (data) {

                    if (foreignpropertyid == undefined || foreignpropertyid == null || foreignpropertyid == "") {
                        for (var i in data) {

                            $("#selectForeignProperty").append("<option value=" + data[i].id + ">" + data[i].property + "</option>");
                        }

                    }
                    else {
                        for (var i in data) {
                            if (foreignpropertyid == data[i].id) {
                                $("#selectForeignProperty").append("<option value=" + data[i].id + " selected>" + data[i].property + "</option>");
                            }
                            else {

                                $("#selectForeignProperty").append("<option value=" + data[i].id + ">" + data[i].property + "</option>");

                            }
                        }
                    }

                }
            })

        }

        //加载项目分类
        function initProjectType() {

            var projecttypeid = "[[${queryMap['projecttypeid']}]]";

            $("#selectProjectType").append("<option value=-1>请选择</option>");
            $.ajax({
                url: '../projectType/selectProjectTypeInfo',
                type: 'get',
                dataType: 'json',
                data: {},
                success: function (data) {

                    if (projecttypeid == undefined || projecttypeid == null || projecttypeid == "") {
                        for (var i in data) {

                            $("#selectProjectType").append("<option value=" + data[i].id + ">" + data[i].projecttype + "</option>");
                        }

                    }
                    else {
                        for (var i in data) {
                            if (projecttypeid == data[i].id) {
                                $("#selectProjectType").append("<option value=" + data[i].id + " selected>" + data[i].projecttype + "</option>");
                            }
                            else {

                                $("#selectProjectType").append("<option value=" + data[i].id + ">" + data[i].projecttype + "</option>");
                            }
                        }
                    }
                }
            })

        }


        //修改提醒字段
        function getVal(id) {
                $.ajax({
                    url: 'eliminateReminding',
                    type: 'get',
                    data: 'id=' + id,
                    success: function () {
                        $('#tr1' + id).css("background-color", "#ffffff")
                    }
                })
        }


        function deleteWorkInfo(id) {

            layer.confirm('确认删除？', {
                btn: ['确认', '取消'] //按钮
            }, function (index) {
                //确认
                //首先关闭弹窗
                layer.close(index);

                $.ajax({
                    url: 'deleteWorkInfo',
                    type: 'get',
                    data: 'id=' + id,
                    success: function () {

                        layer.msg("删除成功!");
                        location.reload();
                    }
                })


            }, function () {
                //取消

            });


        }


        //重置按钮
        $("#resetBtn").on("click", function () {
            $("#selectDepartment").val("-1");

            $("#unitscooperativename").val("");

            $("#selectUnitsNature").val("-1");
            $("#selectCooperativeType").val("-1");
            $("#selectScaleInfo").val("-1");
            $("#selectForeignProperty").val("-1");
            $("#signagreement").val("-1");
            $("#selectAdministrativeDistrict").val("-1");
            $("#selectEnterpriseLocation").val("-1");
            $("#selectProjectType").val("-1");

            $("#beginSignagreement").val("");

            $("#endSignagreement").val("");

        });

        //导出excel
        $("#exportBtn").on("click", function () {
            //查询条件是空则不允许导出
            var selectDepartment = $("#selectDepartment").val();

            var unitscooperativename = $("#unitscooperativename").val();

            var beginSignagreement = $("#beginSignagreement").val();

            var endSignagreement = $("#endSignagreement").val();
            var selectUnitsNature = $("#selectUnitsNature").val();
            var selectCooperativeType = $("#selectCooperativeType").val();
            var selectScaleInfo = $("#selectScaleInfo").val();
            var selectForeignProperty = $("#selectForeignProperty").val();
            var signagreement = $("#signagreement").val();
            var selectAdministrativeDistrict = $("#selectAdministrativeDistrict").val();
            var selectEnterpriseLocation = $("#selectEnterpriseLocation").val();
            var selectProjectType = $("#selectProjectType").val();


            if (selectDepartment == -1 && (unitscooperativename == undefined || unitscooperativename == null || unitscooperativename == "")
                && (beginSignagreement == undefined || beginSignagreement == null || beginSignagreement == "") && (endSignagreement == undefined || endSignagreement == null || endSignagreement == "")
                && selectUnitsNature == -1 && selectCooperativeType == -1 && selectScaleInfo == -1 && selectForeignProperty == -1 && signagreement == -1 && selectAdministrativeDistrict == -1 && selectEnterpriseLocation == -1 && selectProjectType == -1) {
                layer.msg("查询条件不能为空");
            }
            else {

                $("#modularForm").attr("action", "exportExcel");

                $("#modularForm").submit();

                $("#modularForm").attr("action", "queryWorkInfo");

            }


        });


    </script>


</div>
<!-- end: Content -->






